<?php

/**
 * Description of registry
 *
 */
class registry {
    

    #registry meta data => mapped to registry.*
    public $reg_id = 0;
    public $reg_data = array();
    public $renderer_obj;

    public function __construct($id){
        $this->reg_id = $id;
        $this->invoke();
    }
    
    /**
     * LAST HERE
     * @todo : register shutdown function => remove objects
     *         create global class to handle global variables.. means, don't user a common variable. 
     *         all variable should be class variables
     *          no time for security ?
     *         
     */
    private function invoke(){
        $this->reg_data = q("select * from registry left join registry_handler on rh_id = reg_rh_id where reg_id = '{$this->reg_id}'");
        if(empty($this->reg_data)) {
            throw new Exception("Could not map to registry. Registry ID : {$this->reg_id}");
        }
        $this->reg_data = $this->reg_data[0];
        
    }
    /**
     * render the registry here.
     * registry::reg_data['rh_name'] : name of renderer from database
     * 
     * 
     */
    public function process(){
        # if function do not exist, then, throw exception
        if(method_exists('renderer',$this->reg_data['rh_name'])){
            $this->renderer_obj = new renderer();
            call_user_func(array($this->renderer_obj,$this->reg_data['rh_name']), array($this->reg_data['reg_output_format'],$this->reg_data['reg_input_format'],$this->reg_data['reg_path']));
        }
        else{
            throw new Exception("Handler not found. Reg ID : {$this->reg_data['reg_id']}. Reg Handler : {$this->reg_data['rh_name']}");
        }
    }
    
    /**
     * prevent assignment unexpected assignment
     * @param type $name
     * @param type $value
     * @return type 
     */
    public function __set($name,$value) {
        throw new Exception("Trying to assign value to undeclared property '{$name}' of class '" . __CLASS__ ."'");
    }
}

?>
